﻿/********************video.js by sorrycc at 2007-10-22**********************/
Pui.video = {
	init: function() {
		//this.dataConsist(); //数据一致性等接口
		//this.zz(); //转载
		this.emotionWR(); //评论表情写入
		this.emotion(); //评论表情翻页事件
		this.commentReply(); //即时回复
		$('#post_content').bind('focus',function(){CodeImgLoader()});//评论显示
	},
	
	commentLoader: function(e){ //Ajax 读取评论回调
		$('#CommentTemp').remove();
		$('#Comment .title').after(e);
		$("#Comment h3 span").text("20");//更改评论总数量(临时)
		Pui.initManage(userid);
		$('.commentQuote').prepend('<div>引用：</div>');
	},
	hideIntro: function() {
		var str = $('#Layout_1 .vp .v_intro').text();
	},
	hideComment: function(num) {
		if (String(window.location).match(/http:\/\/home.*/)) {
			$('#Comment .mDocument').filter(':gt(19)').hide();
		} else {
			$('#Comment .mDocument').filter(':gt(19)').hide();
		}
		$('#Comment h3 span').html(20);
	},
	emotion: function() {
		var emotionID = 1;
		var emFlag = 2;
		$('#Comment .emotion').find('.l').click(function() {
			if (emotionID >= 2) {
				$('#emotionBox').animate({left: -(500*(emotionID-2))}, 1000);
				if (emotionID == 2) {
					$('#Comment .l').removeClass('l_b').attr('title', '左边没有了');
				} else if (emotionID == 4) {
					$('#Comment .r').addClass('r_b').attr('title', '向右翻');
				}
				emotionID --;
			}
			this.blur();
			return false;
		}).end().find('.r').click(function() {
			if (emotionID <= 3) {
				$('#emotionBox').animate({left: -(500*emotionID)}, 1000);
				if (emotionID == 1) {
					$('#Comment .l').addClass('l_b').attr('title', '向左翻');
				} else if (emotionID == 3) {
					$('#Comment .r').removeClass('r_b').attr('title', '右边没有了');
				}
				emotionID ++;
				if(emFlag == emotionID){ //动态添加表情图标
					s = Pui.video.emotionAdd(emotionID);
					$('#emotionBox').append(s);
					emFlag ++;
				}
			}
			this.blur();
			return false;
		});
		//+zhuxf 2008-3-4 添加验证码代码+
		SetValidCodeImg();
	},
	emVal: function(e){
		var tmp = $('#Comment textarea').val() + '[em'+e+']';
		$('#Comment textarea').val(tmp);
	},
	emotionWR: function() {
		var s = '';
		s += '<div style="position:relative;width:500px;height:60px;overflow:hidden;margin:0 auto;"><div id="emotionBox" style="position:absolute;left:0;top:0;width:100000px;">';
		s += Pui.video.emotionAdd(1);
		s += '</div></div>';
		s += '<a href="" class="l" title="左边没有了">向左翻</a><a href="" class="r r_b" title="向右翻">向右翻</a>';
		$('#Comment .commentAdd .emotion').html(s);
	},
	emotionAdd: function(e) { //动态添加表情图标
		var s = '';
		var l = 'http://static.pomoho.com/images/em/';
		//var l = 'images/';
		var alt = ['Kiss','口水','汗','开心','流鼻血','3Q','有爱','哈','被雷到了','好热','很惨','很冷','很萌啊','火星','闭嘴','囧','泪奔','不屑','萌','萌状','怒','呸','索吻','吐','无语','吓到','邪恶','大跌眼镜','疑问','得意','找死','难过'];		
		s += '<div style="width:500px;float:left;text-align:center;">';
		for(var j=(e-1)*8+1; j<=e*8; j++) {
			s += '<a href="javascript:Pui.video.emVal('+j+');" title="'+alt[j-1]+'"><img src="'+l+'em'+j+'.gif" height="50" /></a>';
		}
		s += '</div>';
		return s;
	},
	commentReply: function() {
		timer_comment = null;
		$('#Comment input[@type=submit]').click(function(){	

			textarea = $('#Comment textarea');
			if ($.trim(textarea.val()) == ''){
				alert('评论内容不可为空！');
				textarea.focus();
				return;
			}
			var sValidCode = "";
			if(document.getElementById("tb_validcode") != null){
				sValidCode = document.getElementById("tb_validcode").value;
				if ($.trim(sValidCode) == ''){
					alert('验证码不可为空！');
					$('#tb_validcode').focus();
					return;
				}
			}
			var scontent = textarea.val().replace("<", "&lt;").replace(">", "&gt;").replace("&", "<--@@-@@-->").replace("\n", " ");
			scontent = escape(scontent);
			Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=7&imdbid=" + $('#hid_starID').val() + "&content=" + scontent + "&validcode=" + sValidCode, {random:true});
			//alert("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=7&imdbid=" + $('#hid_starID').val() + "&content=" + scontent + "&validcode=" + sValidCode, {random:true});
			var ct = Pui.pos.elementTop(document.getElementById('Comment'));
			window.scrollTo(0, ct-30);
			$('#Comment .cl, #Comment .cc').fadeTo('slow', 0.3);
			this.blur();
			setTimeout("Pui.video.commentReplyFill()", 1000);
			GetValidCodeImg();
		});
	},
	commentReplyFill: function() {
		var c = textarea.val().replace(/\[em(\d+)\]/g, "<img src='http://static.pomoho.com/images/em/em$1.gif' />");
		var u = _is_login ? '<a href="javascript:;">'+_user.nick+'</a>' : '游客';
		var s = '';
		s += '<div class="mDocument" style="_width:100%;">';
		s += '	<div class="photo"><img src="http://static.pomoho.com/static/images/photo_68.gif" alt="" /></div>';
		s += '	<div class="detail">';
		s += '		<span class="n_user">'+u+'</span>';
		s += '		<p class="text">'+c+'</p>';
		s += '	</div>';
		s += '	<div class="handle">';
		s += '		<span class="t_release">'+Pui.ui.gettime()+'</span>';
		s += '	</div>';
		s += '</div>';
		
		if($('#Comment h3').length == 0) {
			if (String(window.location).match(/http:\/\/home.*/)) {
				//$('<p class="cc"><a href="javascript:;">查看全部</a>共<span>1</span>条评论</p>').prependTo('#span_video_review');
				$('<div class="cl">'+s+'</div>').prependTo('#span_video_review');
				$('<h3></h3>').prependTo('#span_video_review');
			} else {
				//$('<p class="cc"><a href="javascript:;">查看全部</a>共<span>1</span>条评论</p>').prependTo('#Comment');
				$('<div class="cl">'+s+'</div>').prependTo('#Comment');
				$('<h3></h3>').prependTo('#Comment');
			}
		} else {
			$('#Comment .cl').prepend(s);
			$('#Comment .cl, #Comment .cc').fadeTo('slow', 1);
		}
		textarea.attr('value', '').focus();
	},
	collect: function() {
		if(_is_login){
			Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=2&imdbid=" + flvid);		
		}else{
			flag=2;
			Pui.newSH.loginfo();
		}
		
	},
	delblog: function(blogid) {
		if (window.confirm("确认要删除该条评论吗?")) { 	
			if ($('body').attr('id') == 'SpaceAlbum_Detail') {
				Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=4&blogid=" + blogid+"&imdbid=" + imgid);
			} else{
				Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=4&blogid=" + blogid+"&imdbid=" + flvid);
			}
		}
	},
	quote: function(bid) {
		var re_q_txt = document.getElementById("re_q_"+bid).value;
		document.getElementById("post_content").value = "[quote]"+re_q_txt+"[/quote]";
		$('#Comment textarea').focus();
	},
	clicker:function(tags){
		if(tags==1){
			if($("#HisVideo").length==0)
				Pui.video.AjaxData(flvid);
			else $("#HisVideo").show();
			
			$("#RefVideo").hide();
			$("#Col_ref .title .s2").addClass("s2_a").removeClass("s2").blur();
			$("#Col_ref .title .s1_a").addClass("s1").removeClass("s1_a");
			return
			}else{
			$("#RefVideo").show();
			$("#HisVideo").hide();
			$("#Col_ref .title .s2_a").addClass("s2").removeClass("s2_a");
			$("#Col_ref .title .s1").addClass("s1_a").removeClass("s1").blur();
			}
	}
};

$.fn.currentVideo = function(option) {
	return this.find(option.c).each(function(){
		if($(this).find('.title a').attr('href').indexOf(flvid) != -1) {
			$(this).addClass('ac');
		}
	});
}

//by zhuxf 2008-3-3 评论验证码  type 1 - 视频 2 - 用户  3 - 专题
var ValidCodeURL = "http://www.pomoho.com/do/video/ValidCode.aspx?type=1";

function SetValidCodeImg(){ //主函数，验证Zone写入
	var ValidCodeHtml =  '';
	//ValidCodeHtml = '请输入验证码&nbsp;&nbsp;<input id="tb_validcode" type="text" style="width:60px; border:1px #7B9EBD solid;margin:0 3px 0 0;"><a href="javascript:GetValidCodeImg();" title="看不清楚？请点击刷新验证码！" style="position:relative;top:6px;*top:4px;" ><img id="validcode" border=0  width="60" height="20" src="'+ ValidCodeURL + "&objid=" + typeid +'"></a>';
	ValidCodeHtml = '请输入验证码&nbsp;&nbsp;<input id="tb_validcode" type="text" onfocus="javascript:CodeImgLoader();" style="width:60px; border:1px #7B9EBD solid;margin:0 3px 0 0;" />';
	$('#Comment .commentAdd .form .submit input').before(ValidCodeHtml);
}
function CodeImgLoader(){
	var typeid = $('#hid_starID').val();
	var s = '<a href="javascript:GetValidCodeImg();" title="看不清楚？请点击刷新验证码！" style="position:relative;top:6px;*top:4px;" ><img id="validcode" border=0  width="60" height="20" src="'+ ValidCodeURL + "&objid=" + typeid +'"></a>';
	$('#tb_validcode').after(s).removeAttr('onfocus');
	$('#post_content').unbind('focus');
}
function GetValidCodeImg(){ //图片点击事件 更换验证码
	if(typeof(imgid)!= "undefined"){
		document.getElementById("validcode").src = ValidCodeURL + "&objid=" + imgid + "&ran=" + Math.random();
	}else{
		document.getElementById("validcode").src = ValidCodeURL + "&objid=" + flvid + "&ran=" + Math.random();
	}
}
function SendCallBack(v,sv){ //CallBack回调
	if(v == 0){
		alert("您的验证码错误！");
	}
	if(v == -1){
		alert("您的验证码已失效。请点击验证码图片，重新获取验证码！");
	}
	setTimeout("$('#Comment .mDocument').eq(0).remove();", 1000);
	setTimeout("textarea.attr('value', '"+sv+"').focus();", 1000);
}
